package com.zhitong.money.controller;

import com.zhitong.money.entity.AjaxResponse;
import com.zhitong.money.entity.MsgEmp;
import com.zhitong.money.services.api.IMsgEmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: Andy Zhang
 * @Description:
 * @Date: 11:14 2021/3/5
 * @Company: wisecard
 */
@CrossOrigin
@RestController
public class MsgEmpContro {

    @Autowired
    private IMsgEmpService msgEmpService;

    @GetMapping("/msgEmpByMid/{mid}")
    public AjaxResponse getByMid(@PathVariable String mid) throws Exception{
        List<MsgEmp> msgEmpByMid = msgEmpService.findMsgEmpByMid(mid);
        return AjaxResponse.success(msgEmpByMid);
    }

    @GetMapping("/msgEmpByTid/{tid}")
    public AjaxResponse getByTid(@PathVariable String tid) throws Exception{
        List<MsgEmp> msgEmpByTid = msgEmpService.findMsgEmpByTid(tid);
        return AjaxResponse.success(msgEmpByTid);
    }

    @PostMapping("/msgEmpReaded")
    public AjaxResponse updateReaded(@RequestBody MsgEmp msgEmp) throws Exception{
        msgEmp.setStatus("01");
        msgEmpService.updateStatus(msgEmp);
        return AjaxResponse.success("标记为已读");
    }

    @PostMapping("/delMsgEmp")
    public AjaxResponse updateEnable(@RequestBody MsgEmp msgEmp) throws Exception{
        msgEmp.setEnable("00");
        msgEmpService.updateEnable(msgEmp);
        return AjaxResponse.success("删除成功!");
    }

}
